using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ObjectManager : MonoBehaviour
{

    private static List<ActiveObject> activeObjects = new List<ActiveObject>();
    private static List<PassiveObject> passiveObjects = new List<PassiveObject>();
    private static List<NpcActiveObject> npcActiveObjects = new List<NpcActiveObject>();
    private static ElisActiveObject elisPlayer;
    private static ActiveVector commonVector;

    public static void clearVector()
    {
        commonVector = new ActiveVector();
    }

    public static ActivePrivateVector getVar(string name)
    {
        if (commonVector == null)
            commonVector = new ActiveVector();

        return commonVector.getVar(name);

    }

    public static void pushActiveObject(ActiveObject active)
    {
        activeObjects.Add(active);
    }

    public static void pushPassiveObject(PassiveObject passive)
    {
        passiveObjects.Add(passive);
    }

    public static void pushNpcObject(NpcActiveObject npc)
    {
        npcActiveObjects.Add(npc);
    }

    public static int getMonsterCount(int id)
    {
        int count = 0;
        foreach (ActiveObject obj in activeObjects)
        {
            EnemyActiveObject enemyObj = obj.gameObject.GetComponent<EnemyActiveObject>();
            if (enemyObj && enemyObj.getMonsterID() == id)
                count++;
        }


        return count;
    }

    public static List<ActiveObject> getActiveList()
    {
        return activeObjects;
    }

    public static List<PassiveObject> getPassiveList()
    {
        return passiveObjects;
    }

    public static ActiveObject getElis()
    {
        return elisPlayer;
    }

    public static void refreshActiveList()
    {
        if (activeObjects != null && activeObjects.Count > 0)
        {
            foreach (ActiveObject obj in activeObjects)
            {
                if (obj != null)
                    obj.sendDestroy();

            }
        }
        activeObjects = new List<ActiveObject>();
    }

    public static void refreshPassiveList()
    {
        if (passiveObjects != null && passiveObjects.Count > 0)
        {
            foreach (ActiveObject obj in passiveObjects)
            {
                if (obj != null)
                    obj.sendDestroy();
            }
        }
        passiveObjects = new List<PassiveObject>();
    }

    public static void refreshNpcList()
    {
        if (npcActiveObjects != null && npcActiveObjects.Count > 0)
        {
            foreach (ActiveObject obj in npcActiveObjects)
            {
                if (obj != null)
                    obj.sendDestroy();
            }
        }
        npcActiveObjects = new List<NpcActiveObject>();
    }


    public static void setElis(ElisActiveObject elis)
    {
        elisPlayer = elis;
    }

}
